import { Module } from '@nestjs/common';
import { ScheduleService } from './schedule.service';
import { ScheduleModule as Schedule } from '@nestjs/schedule';
import { ConfigureModule, ConfigureService } from '@app/configure';
import { CacheModule } from '@app/cache';
import { WechatModule } from '@app/wechat';
import { SYS_CONFIG } from 'constant/SYS_CONFIG';
import { DbModule } from './db/db.module';
import { DbService } from './db/db.service';

@Module({
	imports: [
		Schedule.forRoot(),
		ConfigureModule.forRoot(),
		CacheModule,
		
		WechatModule.forRootAsync({
			inject : [DbService],
			useFactory : async (db:DbService) => {
				console.log('----------')
				const configs = await db.sysConfig.selectValues(SYS_CONFIG.wechat)
				return {appid : configs[SYS_CONFIG.appid], secret : configs[SYS_CONFIG.secret]}
			}
		}),

		DbModule,
	],
	providers: [ScheduleService],
})
export class ScheduleModule {}
